﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using clsEmployeeList.BUS;
using System.Data;
using System.Windows.Forms;
using libDAL;
using libAuditTrail;
namespace clsEmployeeList.BUS
{
    public sealed class clsEmpListInterface : clsEmpListBUS, IDisposable 
    {
        struct strcEmployeeDtls
        {
            public string strUserName;
            public int intUserLevel;
            public string strUserPassword;
            public string strLastName;
            public string strFirstName;
            public string strMiddleName;
            public string strHQBranch;
            public string strDesignation;
            public int bolAcctStatus;
            public string strEmployeeID;
        };

        private DataSet dsEmployeeList;
        private DataTable dtEmployeeAccessList;
        private DataSet dsActualAccessList;
        private strcEmployeeDtls strcEmpDetails;

        public clsEmpListInterface()
        {
            dsEmployeeList = new DataSet();
            dtEmployeeAccessList = new DataTable();
            strcEmpDetails = new strcEmployeeDtls();
            dsActualAccessList = new DataSet();
            strcEmpDetails.strEmployeeID = string.Empty;
        }

        public bool get_checkApplistExists()
        {
            bool bolStatus = false;
            if (dtEmployeeAccessList.Rows.Count > 0)
            {
                bolStatus = true;
            }
            

            return bolStatus;
        }

        public DataRow[] get_AllEmployees
        {
            get
            {
                return dsEmployeeList.Tables["EmployeeList-0"].Select();
            }
        }

        public bool set_InsertUpdateRecordsUserProfile(string strEmployeeID, string strFirstName,
                                                       string strLastName, string strMI, string strDesignation,
                                                       string strUserLevel, string strPassword, string strBranch,
                                                       string strLastModifiedBy, string strUserName, int intStatus)
        {
            bool bolStatus = false;
            try
            {


                if (get_CheckEmployeeIDExists(strEmployeeID) == true)
                {
                    //update
                    bolStatus = set_UpdateEmployeeProfile(strEmployeeID, strFirstName,
                                                          strLastName,strMI,strDesignation,
                                                          strUserLevel,strPassword,strBranch,
                                                          strLastModifiedBy, strUserName, intStatus);
                }
                else
                {
                    //insert
                    bolStatus = set_InsertEmployeeProfile(strEmployeeID, strFirstName,
                                                          strLastName, strMI, strDesignation,
                                                          strUserLevel, strPassword, strBranch,
                                                          strLastModifiedBy, strUserName, intStatus);
                }
               
            }
            catch (Exception ex)
            { 
            }

            return bolStatus;
        }

        public bool set_DeleteRecord(string strEmployeeID)
        {
            bool bolStatus = false;
            try
            {
               bolStatus = set_DeleteEmployeeRecord(strEmployeeID);
            }
            catch (Exception ex)
            { 
            }

            return bolStatus;
        }

        public bool set_UnTagAllInUse(string strCurrentUser)
        {
            bool bolStatus = false;
            try
            {
                bolStatus = set_UntagAllOnUse(strCurrentUser);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_clsEmpListInterface_get_TagUnTagOnUse");
            }

            return bolStatus;
        }

        public bool get_TagUnTagOnUse(int intStatus, string strOnUseBy, string strEmployeeID)
        {
            bool bolStatus = false;
            try
            {
                bolStatus = set_TagUnTagOnUse(strEmployeeID,intStatus, strOnUseBy); 
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_clsEmpListInterface_get_TagUnTagOnUse"); 
            }

            return bolStatus;
        }

        public bool get_CheckEmployeeOnUse(string strEmployeeID, string strCurrentUser)
        { 
            bool bolStatus = false;
            try
            {
                bolStatus = get_CheckEmployeeIDOnUse(strEmployeeID, strCurrentUser);
                if (bolStatus == true)
                {
                    MessageBox.Show("Current Profile is on use, try again later."); 
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_clsEmpListInterface_get_CheckEmployeeOnUse"); 
            }

            return bolStatus;
        }

        public bool UpdateUserAccessProfile()
        {
            bool bolStatus = false;

            return bolStatus;
        }

        public DataRow[] get_getSpecificEmployees(string strEmployeeID)
        {
            return dsEmployeeList.Tables["EmployeeList-0"].Select("eiUserName like '*" + strEmployeeID + "*' or eiLastName like '*" + strEmployeeID + "*' or eiFirstname like '*" + strEmployeeID +"*'");     
        }

        public string getset_strUserName
        {
            get
            {
                return strcEmpDetails.strUserName;
               
            }
            set
            {
                strcEmpDetails.strUserName = value;
            }
        }

        public int  getset_intUserLevel
        {
            get
            {
                return strcEmpDetails.intUserLevel;
            }
            set
            {
                strcEmpDetails.intUserLevel = value;
            }
        }

        public string getset_strPassword
        {
            get
            {
                return strcEmpDetails.strUserPassword;
            }
            set
            {
                strcEmpDetails.strUserPassword = value;
            }
        }

        public string getset_LastName
        {
            get
            {
                return strcEmpDetails.strLastName;
            }
            set
            {
                strcEmpDetails.strLastName = value;
            }
        }

        public string getset_FirstName
        {
            get
            {
                return strcEmpDetails.strFirstName;
            }
            set
            {
                strcEmpDetails.strFirstName = value;
            }
        }

        public string getset_MiddleInitial
        {
            get
            {
                return strcEmpDetails.strMiddleName;
            }
            set
            {
                strcEmpDetails.strMiddleName = value;
            }
        }

        public string getset_Designation
        {
            get
            {
                return strcEmpDetails.strDesignation;
            }
            set
            {
                strcEmpDetails.strDesignation = value;
            }
        }

        public string getset_Branch
        {
            get
            {
                return strcEmpDetails.strHQBranch; 
            }
            set
            {
                strcEmpDetails.strHQBranch = value;
            }
        }

        public int getset_UserAccountStatus
        {
            get
            {
                return strcEmpDetails.bolAcctStatus;
            }
            set
            {
                strcEmpDetails.bolAcctStatus = value;    
            }
        }

        public bool set_AppListLoadActual(string strEmployeeID)
        {
            bool bolStatus = false;
            try
            {
                dsActualAccessList = new DataSet();
                set_EmployeeActualAppReport(ref dsActualAccessList, "EmpActAppRepList-1", strEmployeeID);
                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_clsEmpListInterface_set_AppListLoadActual"); 
            }
            return bolStatus;
        }

        public string getset_EmployeeID
        {
            get
            {
                return strcEmpDetails.strEmployeeID;
            }
            set
            {
                strcEmpDetails.strEmployeeID = value;
            }
        }

        public bool get_EmployeeAccessList(string strEmployeeID)
        {
            bool bolStatus = false;
            try
            {
                dtEmployeeAccessList = new DataTable();
                bolStatus = set_EmployeeAccessList(strEmployeeID, ref dtEmployeeAccessList); 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_clsEmpListInterface_set_EmployeeAccessList"); 
            }

            return bolStatus;
        }

        public DataRow[] get_AccessTypeReportProgram(string strType)
        {
            DataRow[] drAccessList= {};
            try
            {
                drAccessList = dtEmployeeAccessList.Select("mdModuleDescription = '" + strType + "'", "mdModuleDescription ASC"); 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_clsEmpListInterface_get_AccessTypeReportProgram"); 
            }
            return drAccessList;
        }

        public DataRow[] get_AccessTypeReportProgram(string strType, string strSearch)
        {
            DataRow[] drAccessList = { };
            try
            {
                drAccessList = dtEmployeeAccessList.Select("mdModuleDescription = '" + strType + "' and mdModulename like '*" + strSearch + "*'");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_clsEmpListInterface_get_AccessTypeReportProgram");
            }
            return drAccessList;
        }

        public DataRow[] get_EmployeeCredentials(string strEmployeeID)
        {
            DataRow[] drEmpCredentials = null;
            try
            {
                drEmpCredentials = dsEmployeeList.Tables["EmployeeList-0"].Select("EmployeeID = '" + strEmployeeID + "'");
                if (drEmpCredentials.Length > 0)
                {
                    getset_strUserName = drEmpCredentials[0]["eiUserName"].ToString().Trim();
                  //  getset_intUserLevel = Convert.ToInt32(drEmpCredentials[0]["eiUserLevel"].ToString().Trim());
                    getset_strPassword = drEmpCredentials[0]["eiPassword"].ToString().Trim();
                    getset_LastName = drEmpCredentials[0]["eiLastName"].ToString().Trim();
                    getset_FirstName = drEmpCredentials[0]["eiFirstname"].ToString().Trim();
                    getset_Designation = drEmpCredentials[0]["eiDesignation"].ToString().Trim();
                    getset_MiddleInitial = drEmpCredentials[0]["eiMiddleName"].ToString().Trim();
                    getset_Branch = drEmpCredentials[0]["eiBranch"].ToString().Trim();
                    getset_UserAccountStatus = clsGenFunction.get_checkComputeNullInt(drEmpCredentials[0]["eiStatus"]);
                }
                else
                { 
                    
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_clsEmpListInterface_get_EmployeeCredentials"); 
            }
            return drEmpCredentials;
        }

        public bool set_EmployeeList()
        { 
            bool bolStatus = false;
            try
            {
                dsEmployeeList = new DataSet();
                bolStatus = get_EmployeeList(ref dsEmployeeList, "EmployeeList-0");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " libEmployeeList_clsEmpListInterface_set_EmployeeList"); 
            }
            return bolStatus ;
        }



       
    }

  
}


